package cn.tutu.blockchain.controller;

import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;

import cn.tutu.blockchain.common.MsgObj;
import cn.tutu.blockchain.common.Page;
import cn.tutu.blockchain.mining.entity.MiningRecords;
import cn.tutu.blockchain.mining.service.MiningRecordsService;

@RestController
@RequestMapping("/miningRec")
public class MiningRecordsController {

	private static Logger LOGGER = LoggerFactory.getLogger(MiningRecordsController.class);
	@Autowired
	private MiningRecordsService miningRecordsService;

	@RequestMapping("/create")
	public MsgObj create(MiningRecords miningRecords, Long miningDatetime) {
		LOGGER.info("添加挖矿记录：矿机ID[{}],currencyValue[{}],miningDatetime[{}]", miningRecords.getEthId(),
				miningRecords.getCurrencyValue(), miningDatetime);

		Date date = new Date(miningDatetime * 1000);
		miningRecords.setMiningTime(date);
		miningRecordsService.create(miningRecords);
		return MsgObj.buildSuccessMsg();
	}

	@RequestMapping("/getGrid")
	public MsgObj getGrid(String ethId, Page page) {
		PageInfo<MiningRecords> byModel = miningRecordsService.getByEthId(ethId, page);
		return MsgObj.buildSuccessObj(byModel.getList());
	}

	@RequestMapping("/getGridByMacId")
	public MsgObj getGridByMacId(String macId, Page page) {
		PageInfo<MiningRecords> byModel = miningRecordsService.getByEthId(macId, page);
		return MsgObj.buildSuccessObj(byModel.getList());
	}

	public static void main(String[] args) {
		System.out.println(System.currentTimeMillis());
		System.out.println(new Date(System.currentTimeMillis()));
	}

}
